import { LINE_LAYOUT, LINE_PAINT } from "./conf";

export const LINE_MODES = ["draw_line_string", "draw_fine_arrow"];

export function generateLineLayer({ map, mode, features }) {
	features.forEach((feature) => {
		feature.properties = {
			...LINE_PAINT,
			...LINE_LAYOUT,
			...feature.properties,
		};
	});

	const lineLayer = {
		id: `${mode}-${features[0].id}-line`,
		type: "line",
		source: {
			type: "geojson",
			data: {
				type: "FeatureCollection",
				features,
			},
		},
		layout: {
			"line-cap": ["get", "lineCap"],
			"line-join": ["get", "lineJoin"],
		},
		paint: {
			"line-color": ["get", "strokeColor"],
			"line-width": ["get", "strokeWidth"],
			"line-dasharray": ["get", "dashArray"],
		},
	};

	map.addLayer(lineLayer);

	return [lineLayer.id];
}

export function isLineMode(mode) {
	return LINE_MODES.includes(mode);
}
